package com.cb.kfc.dao;

import com.cb.kfc.domain.Permission;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface IPermissionDao {

    //查询该角色所有权限
    @Select("select * from permission where id in (select permissionId from role_permission where roleId=#{id} )")
    public List<Permission> findPermissionByRoleId(String id) throws Exception;
    //查询所有权限
    @Select("select * from permission")
    List<Permission> findAll() throws Exception;
    //增加权限
    @Insert("insert into permission(permissionName,url) values(#{permissionName},#{url})")
    void save(Permission permission) throws Exception;
    //查询单个权限的详情
    @Select("select * from permission where id=#{id}")
    Permission findById(String id) throws Exception;
////？？？什么方法？
//    @Delete("delete from role_permission where permissionId=#{id}")
//    void deleteFromRole_Permission(String id) throws Exception;
////删除单个权限
//    @Delete("delete from permission where id=#{id}")
//    void deleteById(String id) throws Exception ;

    //有外键约束，先删子表，再删主表
    // 删除单个，或者批量删除
    @Delete("<script>delete from role_permission where RoleId in <foreach collection='array' item='id' open='(' separator=',' close=')'>#{id}</foreach> </script>")
    Integer deleteRP(String[] ids);

    @Delete("<script>delete from permission where id in <foreach collection='array' item='id' open='(' separator=',' close=')'>#{id}</foreach> </script>")
    Integer deleteP(String[] ids);
}
